import request from '@/config/axios'
import { MenuTree } from '@/api/system/role/types'
import { SystemMenu, SystemMenuQuery } from '@/api/system/menu/types'
import { SelectTreeOption } from '@/api/common/types'

export const getSystemMenuListApi = (data: SystemMenuQuery): Promise<IResponse<SystemMenu[]>> => {
  return request.get({ url: '/system/menu/list', data })
}
export const getAllUsableMenuTreeApi = (): Promise<IResponse<MenuTree[]>> => {
  return request.get({ url: '/system/menu/usable/tree' })
}

export const getRoleMenuListApi = (roleId: number): Promise<IResponse<number[]>> => {
  return request.get({ url: '/system/role/menu', params: { roleId: roleId } })
}

export const createSystemMenuApi = (data: SystemMenu): Promise<IResponse<SystemMenu>> => {
  return request.post({ url: '/system/menu/add', data })
}

export const updateSystemMenuApi = (data: SystemMenu): Promise<IResponse<SystemMenu>> => {
  return request.post({ url: '/system/menu/update', data })
}

export const checkMenuCodeApi = (params) => {
  return request.get({ url: '/system/menu/code/check', params })
}

export const getUsableMenuListApi = (): Promise<IResponse<SelectTreeOption[]>> => {
  return request.get({ url: '/system/menu/usable/list' })
}
